import { takeEvery, put } from 'redux-saga/effects'

// import * as API from '../API/index.js'
import * as actions from '../actionTypes/'


let delay =  (ms, result = ms)=> {
	return new Promise(resolve => {
	  setTimeout(() => resolve(result), ms)
	})
  }

export function* handleToast({ payload }) {
	yield put({
		type: actions.TOGGLE_DISPLAY_TOAST,
		payload: {
			showToast: true,
			toastContent: payload,
		},
	})

	yield delay(2000)

	yield put({
		type: actions.TOGGLE_DISPLAY_TOAST,
		payload: { showToast: false },
	})
}

export default function* watchCommons() {
	yield takeEvery(actions.SHOW_TOAST, handleToast)
}



// WEBPACK FOOTER //
// ./src/sagas/common.js